import { addUserUsingPost } from '@/services/backend/userController';
import { ProColumns, ProFormUploadDragger } from '@ant-design/pro-components';
import '@umijs/max';
import { message, Modal } from 'antd';
import React from 'react';

interface Props {
  modalVisible: boolean;
  columns: ProColumns<API.User>[];
  onSubmit: () => void;
  onCancel: () => void;
}

/**
 * @en-US Add node
 * @zh-CN 添加节点
 * @param fields
 */
const handleAdd = async (fields: API.UserAddRequest) => {
  const hide = message.loading('正在添加');
  try {
    await addUserUsingPost({
      ...fields,
    });
    hide();
    message.success('创建成功');
    return true;
  } catch (error: any) {
    hide();
    message.error(`创建失败,${error.message}`);
    return false;
  }
};

const CreateModal: React.FC<Props> = (props) => {
  const { modalVisible, onSubmit, onCancel } = props;

  return (
    <Modal title={'上传'} open={modalVisible} destroyOnClose footer={null} onCancel={onCancel}>
      <ProFormUploadDragger
        max={4}

        name="dragger"
        fieldProps={{
          name: 'file',
        }}
      />
      {/*<ProTable*/}
      {/*  type={'form'}*/}
      {/*  columns={columns}*/}
      {/*  onSubmit={async (value) => {*/}
      {/*    const success = await handleAdd(value);*/}
      {/*    if (success) {*/}
      {/*      onSubmit?.();*/}
      {/*    }*/}
      {/*  }}*/}
      {/*/>*/}
    </Modal>
  );
};
export default CreateModal;
